package ar.com.digitalbricks.imprenta.persona.enums;

import java.math.BigDecimal;

public enum Horario {
	OCHO,
	OCHO_30,
	NUEVE,
	NUEVE_30,
	DIEZ,
	DIEZ_30,
	ONCE,
	ONCE_30,
	DOCE,
	DOCE_30,
	TRECE,
	TRECE_30,
	CATORCE,
	CATORCE_30,
	QUINCE,
	QUINCE_30,
	DIECISEIS,
	DIECISEIS_30,
	DIECISIETE,
	DIECISIETE_30,
	DIECIOCHO,
	DIECIOCHO_30;
	
	public int getCalendarHourOrdinal(){
		switch (this.ordinal()) {
		case 0:
			return 8;
		case 1:
			return 8;
		case 2:
			return 9;
		case 3:
			return 9;
		case 4:
			return 10;
		case 5:
			return 10;
		case 6:
			return 11;
		case 7:
			return 11;
		case 8:
			return 12;
		case 9:
			return 12;
		case 10:
			return 13;
		case 11:
			return 13;
		case 12:
			return 14;
		case 13:
			return 14;
		case 14:
			return 15;
		case 15:
			return 15;
		case 16:
			return 16;
		case 17:
			return 16;
		case 18:
			return 17;
		case 19:
			return 17;
		case 20:
			return 18;
		case 21:
			return 18;
		default:
			return 100;
		}
	}
	
	public int getCalendarMinuteOrdinal(){
		BigDecimal min = new BigDecimal(this.ordinal());
		return min.remainder(new BigDecimal("2")).intValue()*30;
	}

	public static Horario get(int hour, int min) {
		Horario h;
		switch (hour) {
		case 8:
			h = Horario.OCHO;
			break;
		case 9:
			h = Horario.NUEVE;
			break;
		case 10:
			h = Horario.DIEZ;
			break;
		case 11:
			h = Horario.ONCE;
			break;
		case 12:
			h = Horario.DOCE;
			break;
		case 13:
			h = Horario.TRECE;
			break;
		case 14:
			h = Horario.CATORCE;
			break;
		case 15:
			h = Horario.QUINCE;
			break;
		case 16:
			h = Horario.DIECISEIS;
			break;
		case 17:
			h = Horario.DIECISIETE;
			break;
		case 18:
			h = Horario.DIECIOCHO;
			break;
		default:
			return null;
		}
		if (min == 0){
			return h;
		}else{
			return Horario.valueOf(h.toString() + "_30");
		}
	}
}